package com.example.lvsuo.service.impl;

import com.example.lvsuo.entity.vo.CaseSealApplyforVo;
import com.example.lvsuo.service.ICaseSealApplyforService;
import com.example.lvsuo.entity.CaseSealApplyfor;
import com.example.lvsuo.mapper.CaseSealApplyforMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 案件/用印申请 服务实现类
 * </p>
 *
 * @author 心心念念
 * @since 2021-03-30
 */
@Service
@Transactional
public class CaseSealApplyforServiceImpl extends ServiceImpl<CaseSealApplyforMapper, CaseSealApplyfor> implements ICaseSealApplyforService {

    @Autowired
    CaseSealApplyforMapper cm;

    @Override
    public void addBatch(CaseSealApplyforVo c) {
        List<CaseSealApplyfor> list=new ArrayList<>();
        for (int i = 0; i < c.getApplyforUsingTheItem().size(); i++) {
            CaseSealApplyfor caseSealApplyfor = new CaseSealApplyfor();
            caseSealApplyfor.setCaseid(c.getCaseid());
            caseSealApplyfor.setCaseNo(c.getCaseNo());
            caseSealApplyfor.setApplyforReceive(c.getApplyforReceive());
            caseSealApplyfor.setApplyforRecipient(c.getApplyforRecipient());
            caseSealApplyfor.setSendPerson(c.getSendPerson());
            caseSealApplyfor.setApplyforUsingTheItem(c.getApplyforUsingTheItem().get(i));
            caseSealApplyfor.setFilepath(c.getFilepath());
            list.add(caseSealApplyfor);
        }
        cm.addBatch(list);
    }

    @Override
    public CaseSealApplyfor queryCaseSealApplyfor(String id) {
        return cm.queryCaseSealApplyfor(id);
    }

    @Override
    public List<CaseSealApplyforVo> queryCaseSeal(String id) {
        return cm.queryCaseSeal(id);
    }

    @Override
    public PageInfo querySeal(CaseSealApplyforVo c) {
        if(c.getPageNum()==null){
            c.setPageNum(1);
        }
        if(c.getPageSize()==null){
            c.setPageSize(5);
        }
        PageHelper.startPage(c.getPageNum(),c.getPageSize());
        return new PageInfo(cm.querySeal(c));
    }
}
